import 'package:merchants/models/merchant.dart';
import 'package:merchants/services/base-service.dart';

class MerchantSecretService extends BaseService {
  MerchantSecretService({required super.ref});

  Future<bool> checkSecret(String merchantId) async {
    try {
      final response = await post<Map<String, dynamic>>(
        '/secret/get',
        body: {'merchantId': merchantId},
        parser: (json) {
          if (json['success'] != true) {
            throw ApiException(json['message'] ?? '获取用户信息失败');
          }
          return json;
        },
        requireToken: false,
      );
      return response['data'] as bool;
    } catch (e) {
      throw ApiException('获取商户列表失败: $e');
    }
  }

  Future<bool> createSecret(String merchantId) async {
    try {
      final response = await post<Map<String, dynamic>>(
        '/secret/create',
        body: {'merchantId': merchantId},
        parser: (json) {
          if (json['success'] != true) {
            throw ApiException(json['message'] ?? '生成 appSecret 失败');
          }
          return json;
        },
        requireToken: false,
      );

      return response['data'] as bool;
    } catch (e) {
      throw ApiException('生成 appSecret 失败: $e');
    }
  }
}
